package com.tianchi.lexiang.background;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;

import com.tianchi.lexiang.R;
import com.tianchi.lexiang.background.adapter.BackgroundSettingAdapter;
import com.tianchi.lexiang.background.util.PublicUtil;
import com.tianchi.lexiang.bean.LeXiangConstants;

public class BackgroundSetting extends Activity implements OnItemClickListener {

	private static final String TAG = "BackgroundSetting";
	private PublicUtil publicUtil = PublicUtil.getPulibUtil();

	private ListView backgroundSettingList;
	private Button backBtn;

	public static BackgroundSetting mBackgroundSetting;

	private String[] titleStrs;

	private BackgroundSettingAdapter mAdapter;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.background_setting);
		initView();
	}

	private void initView() {
		mBackgroundSetting = this;
		backgroundSettingList = (ListView) findViewById(R.id.background_setting_list);
		backBtn = (Button) findViewById(R.id.back_btn);
		titleStrs = getResources().getStringArray(R.array.title);
		Log.d(TAG, "[initView]....titleStrs.length===>" + titleStrs.length);
		mAdapter = new BackgroundSettingAdapter(this, titleStrs);
		backgroundSettingList.setAdapter(mAdapter);
		backgroundSettingList.setOnItemClickListener(this);
		mAdapter.startAddTitle();
		backBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				BackgroundSetting.this.finish();
			}
		});

	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		Intent intent = new Intent();
		switch (position) {
		case 0:
			intent.setClass(BackgroundSetting.this, SongCheck.class);
			BackgroundSetting.this.startActivity(intent);
			break;
		case 1:
			intent.setClass(BackgroundSetting.this, SingerCheck.class);
			BackgroundSetting.this.startActivity(intent);
			break;
		case 2:
			if (publicUtil.detectionuDisk(LeXiangConstants.SONG_UDISK_PAHT)) {
				intent.setClass(BackgroundSetting.this, UdiskAddsong.class);
				BackgroundSetting.this.startActivity(intent);
			} else {
				dialog(getString(R.string.udisk_add_songs_tip));
			}
			break;
		case 3:
			intent.setClass(BackgroundSetting.this, NetworkAddSong.class);
			BackgroundSetting.this.startActivity(intent);
			break;
		case 4:
			intent.setClass(BackgroundSetting.this, DeleteSong.class);
			BackgroundSetting.this.startActivity(intent);
			break;
		case 5:
			if (publicUtil.detectionuDisk(LeXiangConstants.SINGER_UDISK_PATH)) {
				intent.setClass(BackgroundSetting.this, SingerAdd.class);
				BackgroundSetting.this.startActivity(intent);
			} else {
				dialog(getString(R.string.udisk_add_singer_tip));
			}
			break;
		case 6:
			intent.setClass(BackgroundSetting.this, NetworkSetting.class);
			BackgroundSetting.this.startActivity(intent);
			break;
		case 7:
			intent.setClass(BackgroundSetting.this, OsdSetting.class);
			BackgroundSetting.this.startActivity(intent);
			break;
		case 8:
			intent.setClass(BackgroundSetting.this, PublicSongSetting.class);
			BackgroundSetting.this.startActivity(intent);
			break;
		case 9:
			intent.setClass(BackgroundSetting.this, SameScreenSetting.class);
			BackgroundSetting.this.startActivity(intent);
			break;
		case 10:
			intent.setClass(BackgroundSetting.this, ClickRateReset.class);
			BackgroundSetting.this.startActivity(intent);
			break;
		case 11:
			intent.setClass(BackgroundSetting.this, PwdSetting.class);
			BackgroundSetting.this.startActivity(intent);
			break;
		default:
			break;
		}

	}

	private void dialog(String tip) {
		AlertDialog.Builder builder = new Builder(BackgroundSetting.this);
		builder.setMessage(tip);
		builder.setIcon(android.R.drawable.ic_menu_info_details);
		builder.setTitle("ÌáÊ¾");
		builder.setPositiveButton("È·ÈÏ", new Dialog.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
			}
		});
		builder.create().show();
	}
}